package lambdademo;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

public class Test2 {
    public static void main(String[] args) {
        HashMap<Integer, String> map = new HashMap<>();
        map.put(1, "hello");
        map.put(2, "bit");
        map.put(3, "hello");
        map.put(4, "lambda");
        /*map.forEach(new BiConsumer<Integer, String>(){
            @Override
            public void accept(Integer k, String v){
                System.out.println("key:"+k + "value:" + v);
            }
        });*/
        map.forEach((key,val)-> System.out.println("key:"+key + " value:" + val));
    }
    public static void main1(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("bit");
        list.add("aello");
        list.add("hello");
        list.add("lambda");
        /*list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });*/
        System.out.println("=============================");
        list.forEach(s -> System.out.println(s));
        System.out.println("排序：");
       /* list.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });*/
        list.sort((o1, o2) -> o1.compareTo(o2));
        list.forEach(s -> System.out.println(s));

    }
}
